<?php
/**
 * Element-Klasse zu Html-Scanner zur Ausgabe und Weiterverarbeitug von Html-Tags
 *
 * @author		Joachim Ruf
 * @copyright	Copyright (c) 2003-2013 Loresoft Software (http://www.loresoft.de)
 * @license		http://yapary.loresoft.de/lizenzbedingungen     New BSD License
 * @TODO
 * */


Class Yapary_WWW_Html_Element
{
    private $arrContent = array();
    private $oTag       = NULL;


    function __construct($_arrContent) {
        $this->arrContent = $_arrContent;
        $this->oTag    = new Yapary_WWW_Html_Tag();
    }

    /**
	 * Gibt den Tag-Inhalt aus
	 * @return string
	 * */
    public function getInner () {
        if (!isset($this->arrContent[4])) {
            return '';
        }
        return $this->arrContent[4];
    }

    /**
	 * Gibt den Tag-Inhalt aus
	 * @return Yapary_WWW_Html_Attribute|NULL
	 * */
    public function getInnerAttribute () {
        if (!isset($this->arrContent[4])) {
            return NULL;
        }

        return new Yapary_WWW_Html_Attribute($this->arrContent[4]);
    }

    /**
	 * Gibt den Inhalt inklusive Tag aus
	 * @return string
	 * */
    public function getOuter () {
        return $this->arrContent[2];
    }

    /**
	 * Gibt den Inhalt inklusive Tag aus
	 * @return string
	 * */
    public function getType () {
        $pattern = "<([a-z]{1,})\s*.*?\/?\s*>";
        if (!preg_match($pattern,$this->arrContent[3], $result)) {
            return NULL;
        }

        return $result[0];
    }

    /**
	 * gibt die Attributklasse aus
	 * @return Yapary_WWW_Html_Attribute
	 * */
    public function getAttribute () {
        return new Yapary_WWW_Html_Attribute($this->arrContent[3]);
    }

    /**
	 * gibt die Attributklasse aus
	 * @return Yapary_WWW_Html_Scanner
	 * */
    public function getScanner () {
        if ($this->getInner() != '') {
            return new Yapary_WWW_Html_Scanner($this->getInner());
        }

        return new Yapary_WWW_Html_Scanner('');
    }

    /**
	 * Wandelt br gegen nl
	 * @param string $content    : Zu tauschender Content
	 * @return srting
	 * */
    public function br2nl ($content) {
		return str_replace(array('<br />', '<br>'), chr(32), $content);

    }


}

?>